﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject_SEM3_SecurityServices.Bussiness;
using eProject_SEM3_SecurityServices.ObjectClass;

namespace eProject_SEM3_SecurityServices
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        BCustomerServices bcs = null;
        BService bs = null;
        BEmployee be = null;
        BCustomer bc = null;
        BContract bcontract = null;
        BContractDetail bcd = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            bcs = new BCustomerServices();
            bs = new BService();
            be = new BEmployee();
            bc = new BCustomer();
            bcontract = new BContract();
            bcd = new BContractDetail();
            BindDataDdlService();

        }


        public void BindDataDdlService()
        {
            ddlService.DataSource = bs.getServiceList();
            ddlService.DataTextField = "serviceName";
            ddlService.DataValueField = "serviceId";
            ddlService.DataBind();
        }


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            OCustomer customer = new OCustomer();
            customer.CustomerName = txtName.Text;
            customer.CustomerAddress = txtAddress.Text;
            customer.CustomerPhone = txtPhone.Text;
            bc.AddCustomer(customer);

            OContractDetail contractdetail = new OContractDetail();
            contractdetail.ContractId = bcd.getContractDetailList().Count() + 1;
            contractdetail.StartDay = txtStart.Text;
            contractdetail.EndDay = txtEndDay.Text;
            contractdetail.NumberEmployee = Convert.ToInt32(txtnumberEmp.Text);
            contractdetail.CustomerId = getCustomerID();
            contractdetail.RegistryDay = txtRegistryDay.Text;
            bcd.AddNewContractDetail(contractdetail);

            OContract contract = new OContract();
            contract.ServiceId = Convert.ToInt32(ddlService.SelectedValue);
            contract.ContractId = bcd.getContractDetailList().Count();
            bcontract.AddNewContract(contract);

            Label1.Text = "Success";
        }

        public int getCustomerID()
        {
            return bc.getCustomerList().Count();
        }
    }
}